package net.entelijan.cobean.bind.impl;

import java.util.Arrays;
import java.util.List;

import net.entelijan.cobean.bind.IModelChangeListener;

import org.aopalliance.aop.Advice;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.support.AbstractGenericPointcutAdvisor;
import org.springframework.aop.support.RegexpMethodPointcutAdvisor;

class DefaultModelWrapper extends AbstractModelWrapper {
    
    private static Log log = LogFactory.getLog(DefaultModelWrapper.class);

    public DefaultModelWrapper() {
        super();
    }

    protected AbstractGenericPointcutAdvisor createGenericPointcutAdvisor() {
        RegexpMethodPointcutAdvisor re = new RegexpMethodPointcutAdvisor();
        String[] patterns = new String[] { ".*set[a-zA-Z0-9_]*()", ".*add()", ".*remove()" };
        re.setPatterns(patterns);
        log.debug("[createGenericPointcutAdvisor] RegexpMethodPointcutAdvisor patterns=" + Arrays.toString(patterns));
        return re;
    }

    protected Advice createAdvice(List<IModelChangeListener> modelChangeListeners) {
        PropertyChangedAdvice advice = new PropertyChangedAdvice();
        advice.setModelChangeListeners(modelChangeListeners);
        log.debug("[createAdvice] PropertyChangedAdvice");
        return advice;
    }

}
